<?php 
class OAuthAction extends Action{
	public function a(){
		$r=$this->_get('r');

		$oaRecord=M('oauth')->where(array('r'=>$r))->find();
		$url=$oaRecord['url'];
		//echo $r.'='.$url.'='.M('oauth')->getLastSql();exit;
		$token=$this->_get('token');
		$code=$this->_get('code');
		//$state=$this->_get('state');
		//echo 'state:'.$state.'; code:'.$code.'; url:'.$url;exit;
		$diymen=M('diymen_set')->where(array('token'=>$token))->find();
		$url_get='https://api.weixin.qq.com/sns/oauth2/access_token?appid='.$diymen['appid'].'&secret='.$diymen['appsecret'].'&code='.$code.'&grant_type=authorization_code';
		$result=WechatAdvanceAPI::https_get($url_get);
		$json=json_decode($result);
		$openid=$json->openid;
		//echo $openid;exit;
		$this->redirect($url, array('token'=>$token, 'openid'=>$openid));
	}
}
?>